﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using Telerik.Web.UI;
using System.Data;
using System.Collections;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
//using Microsoft.Office.Interop.Excel;
//using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class PS_EmployeeFind : System.Web.UI.Page
    {
        CommandControlBLL cmdFac = new CommandControlBLL();
        private IJobSiteBLL jobsiteBLL = new JobSiteBLL();
        private IEmployeeTypeBLL etBLL = new EmployeeTypeBLL();
        private IPositionTypeBLL ptBLL = new PositionTypeBLL();
        private IEmployeeBLL empBLL = new EmployeeBLL();
        private IFieldBLL fieldBLL = new FieldBLL();
        private IClassBLL classBLL = new ClassBLL();
        private IMasEducationDegreeBLL dBLL = new MasEducationDegreeBLL();
        private IMasEducationQualificationBLL qualBLL = new MasEducationQualificationBLL();
        private IMasEducationMajorBLL majorBLL = new MasEducationMajorBLL();
        private IMasEducationInstituteBLL insBLL = new MasEducationInstituteBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cmdFac.EditCommand(panelList, panelGrid, panelCommand);                
            }
        }
        public DataTable GetResult()
        {
            DataTable dt = null;
            string EmpTypeSeq = cmbEmployeeType.SelectedValue;
            string JobSiteSeq = cmbJobSite.SelectedValue;
            string WorkingJobSiteSeq = cmbWorkingJobSite.SelectedValue;

            //DataSet ds = empBLL.LoadToExcel(EmpTypeSeq, JobSiteSeq, ""
            //    , ListCheckedItems(cblPosType)
            //    , ListCheckedItems(cblClass1)
            //    , ListCheckedItems(selectFieldPosition)
            //    , ListCheckedItems(selectDegree)
            //    , ListCheckedItems(selectQual)
            //    , ListCheckedItems(selectMajor)
            //    , ListCheckedItems(selectInstitutes)
            //    , 0, (DateTime?)null, 0, (DateTime?)null, (int?)null, (int?)null, true);

            //if (ds.Tables.Count > 0)
            //    dt = ds.Tables[0].Copy();
            return dt;
        }
        protected void ShowGrid_Click(object sender, EventArgs e)
        {
            LoadDataGrid();
        }
        public void LoadDataGrid()
        {
            Grid.DataSource = GetResult();
            Grid.DataBind();

            cmdFac.GridCommand(panelList, panelGrid, panelCommand);
        }
        private void LoadListBoxEduQual(string bgm_prj_header_seq)
        {
            Nullable<int> eduDegree = string.IsNullOrEmpty(cmbDegree.SelectedValue) ? null : (Nullable<int>)Int32.Parse(cmbDegree.SelectedValue);
            
            DataSet ds = qualBLL.LoadEducationQualifications((int?)null, eduDegree, "");
            DataTable info = null;
            if (ds.Tables.Count > 0)
            {
                info = ds.Tables[0].Copy();
            }
            lstEduQual.DataValueField = "edu_qual_seq";
            lstEduQual.DataTextField = "edu_qual_name";
            lstEduQual.DataSource = info;
            lstEduQual.DataBind();
            checkItems();
        }
        protected void checkItems()
        {
            for (int r = lstEduQual.Items.Count - 1; r >= 0; r--)
            {
                for (int a = selectEduQual.Items.Count - 1; a >= 0; a--)
                {
                    if (lstEduQual.Items[r].Text == selectEduQual.Items[a].Text)
                    {
                        lstEduQual.Items.Remove(lstEduQual.Items[r]);
                    }
                    continue;
                }
            }
        }

        protected void btnSelect_Cleck(object sender, EventArgs e)
        {
            for (int i = lstEduQual.Items.Count - 1; i >= 0; i--)
            {
                if (lstEduQual.Items[i].Selected)
                {
                    selectEduQual.Items.Add(new ListItem(lstEduQual.Items[i].Text, lstEduQual.Items[i].Value));
                    lstEduQual.Items.Remove(lstEduQual.Items[i]);
                }
            }
        }

        protected void btnSelectAll_Cleck(object sender, EventArgs e)
        {
            for (int i = lstEduQual.Items.Count - 1; i >= 0; i--)
            {
                selectEduQual.Items.Add(new ListItem(lstEduQual.Items[i].Text, lstEduQual.Items[i].Value));
                lstEduQual.Items.Remove(lstEduQual.Items[i]);
            }
        }

        protected void btnRemove_Cleck(object sender, EventArgs e)
        {
            for (int i = selectEduQual.Items.Count - 1; i >= 0; i--)
            {
                if (selectEduQual.Items[i].Selected)
                {
                    lstEduQual.Items.Add(new ListItem(selectEduQual.Items[i].Text, selectEduQual.Items[i].Value));
                    selectEduQual.Items.Remove(selectEduQual.Items[i]);
                }
            }
        }

        protected void btnRemoveAll_Cleck(object sender, EventArgs e)
        {
            for (int i = selectEduQual.Items.Count - 1; i >= 0; i--)
            {
                lstEduQual.Items.Add(new ListItem(selectEduQual.Items[i].Text, selectEduQual.Items[i].Value));
                selectEduQual.Items.Remove(selectEduQual.Items[i]);
            }
        }

        protected void AddNew_Click(object sender, EventArgs e)
        {
            LoadDataGrid();
        }
    }
}
